import 'package:flutter/material.dart';
import 'package:flutter_list_view/flutter_list_view.dart';
import '../model/title_subtitle_model.dart';
import 'learn_base_router_a_page.dart';
import 'learn_base_router_b_page.dart';
import 'learn_base_router_c_page.dart';
import 'learn_tab_router_page.dart';

class LearnRouterPage extends StatelessWidget {
  const LearnRouterPage({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
          useMaterial3: true,
        ),
        initialRoute: "/",
        routes: {
          "/":(context) => const LearnRouterAppPage(),
          "/A":(context) => const LearnBaseRouterAPage(),
          "/B":(context) => const LearnBaseRouterBPage(),
          "/C":(context) => const LearnBaseRouterCPage(),
          "/tab":(context) => const LearnTabRouterPage()
        },
    );
  }
}

class LearnRouterAppPage extends StatefulWidget {
  const LearnRouterAppPage({super.key});
  @override
  State<LearnRouterAppPage> createState() => _LearnRouterAppPageState();
}

class _LearnRouterAppPageState extends State<LearnRouterAppPage> {
  final List<TitleSubTitleModel> _dataList = [
    TitleSubTitleModel("基础路由","基础路由的基本和进阶用法"),
    TitleSubTitleModel("Tab","Tab中路由的一些用法"),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text("路由"),
      ),
      body: FlutterListView(
          delegate: FlutterListViewDelegate(
                (BuildContext context, int index) {
              TitleSubTitleModel model = _dataList[index];
              return ListTile(
                  title: Text(model.title),subtitle: Text(model.subTitle),
                  onTap: () {
                    switch(index) {
                      case 0:
                        Navigator.pushNamed(context, '/A');
                        break;
                      case 1:
                        Navigator.pushNamed(context, '/tab');
                        break;
                    }
                  });
            },
            childCount: _dataList.length,
          )), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
